#include<iostream>
#include<vector>
#include<algorithm>
#include"HeightComputation.h"

using namespace std;
#define  PI 3.1415926


void test1()
{
	HeightField * h1;
	h1 = new HeightField();
	h1->computeKVector();
	h1->computeWk();
	h1->computeInitialHeight();
	h1->writeInitialHeight();

}


void test2()
{
	fstream fileIn;
	fileIn.open("E://data1//height8.txt",ios::in);
	double * a = new double[128*128];
	for(int i=0;i<128;i++)
	{
		for(int j =0;j<128;j++)
		{
			fileIn>>a[i*128+j];
			if((((i%2)==0)&&((j%2)==1))||(((i%2)==1)&&((j%2)==0)))
				a[i*128+j]=(-a[i*128+j]);
		}
	}
	fileIn.close();

	fstream fileOut;
	fileOut.open("E://data1//height9.txt",ios::out);

	for(int i=0;i<128;i++)
	{
		for(int j =0;j<128;j++)
		{
			fileOut<<a[i*128+j]<<'\t';
		}
	}
	fileOut.close();

	/*fileOut.open("E://data2//output//height301.txt",ios::out);

	for(int i=0;i<128;i++)
	{
		for(int j =0;j<55;j++)
		{
			fileOut<<a[i*55+j]<<'\t';
		}
	}
	fileOut.close();
	*/

}


double gauss()
{
	float u1 = rand() / (float)RAND_MAX;
	float u2 = rand() / (float)RAND_MAX;
	if (u1 < 1e-6f)
		u1 = 1e-6f;
	return sqrt(-2 * log(u1)) * cos(2*PI * u2);
}

void test3()
{
	srand(0);
	double temp =0;
	double temp1=0;
	double stnd = 0;
	double avg = 0;
	double * r  = new double[1000];
	for(int i=0;i<1000;i++)
	{
		r[i]=gauss();
		temp+=r[i];
		//cout<<gauss()<<endl;
	}
	avg = temp / 1000;
	for(int i=0;i<1000;i++)
	{
		temp1+=((r[i]-avg)*(r[i]-avg));
		//cout<<gauss()<<endl;
	}
	stnd = sqrt((temp1/1000));
	cout<<avg<<endl;
	cout<<stnd<<endl;
}

void main()
{
	//test1();
	test2();	
	//test3();
	system("pause");
	
}